part of '../index.dart';

class _RoomCard extends StatelessWidget {
  _RoomCard(this.model);
  final RoomSearchModel model;

  Color _getColorFromHex(String hexColor) {
    hexColor = hexColor.replaceAll("#", "");
    if (hexColor.length != 6) return Colors.white;
    return Color(int.parse(hexColor, radix: 16) + 0xFF000000);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(bottom: 10, left: 15, right: 15),
      padding: const EdgeInsets.all(8),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
      ),
      child: Row(
        children: [
          image(
            model.roomIcon ?? '',
            width: 90,
            height: 90,
            fit: BoxFit.fitWidth,
            errorWidget: (a, b, c) {
              return Container(
                width: 90,
                height: 90,
                color: Colors.red,
              );
            },
          ).clipRRect(8),
          const SizedBox(width: 15),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  if (model.countryUrl != null)
                    image(
                      model.countryUrl!,
                      width: 24,
                      height: 16,
                      fit: BoxFit.fill,
                    ),
                  Text(
                    model.roomName ?? '',
                    maxLines: 1,
                    style: const TextStyle(
                      fontWeight: FontWeight.w600,
                      fontSize: 16,
                    ),
                  ).expanded,
                ],
              ),
              Text(
                model.slogan ?? '',
                maxLines: 2,
                style: const TextStyle(color: Color(0xFFC1C1C1), fontSize: 13),
              ),
              const SizedBox(height: 10),
              Row(
                children: [
                  if (model.categoryTypeIcon != null)
                    image(
                      model.categoryTypeIcon ?? '',
                      width: 24,
                      height: 24,
                      fit: BoxFit.fill,
                    ),
                  Container(
                    margin: const EdgeInsets.only(left: 5),
                    padding:
                        const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
                    decoration: BoxDecoration(
                      color: _getColorFromHex(model.roomCategoryColor ?? '')
                          .withOpacity(0.2),
                      borderRadius: BorderRadius.circular(99),
                    ),
                    child: Text(
                      model.roomCategoryName ?? '',
                      style: TextStyle(
                        color: _getColorFromHex(model.roomCategoryColor ?? ''),
                        fontSize: 12,
                      ),
                    ),
                  ),
                  const Spacer(),
                  Image.asset(Images.icChatFire, width: 15, height: 15),
                  Text(
                    '${model.scoreWeight ?? ''}',
                    style: const TextStyle(
                      color: Color(0xFFC1C1C1),
                      fontSize: 13,
                    ),
                  )
                ],
              )
            ],
          ).expanded,
        ],
      ),
    ).onTap(() {
      /// 跳转到房间
      if (model.roomNo != null) {
        RoomPage.show(context, model.roomNo!);
      }
    });
  }
}
